package com.example.blueconn.conn;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.net.NetworkInfo;
import android.net.wifi.WifiManager;

public class WifiStateBroadcastReceiver extends BroadcastReceiver {
    @Override
    public void onReceive(Context context, Intent intent) {
        if (intent != null) {
            if (WifiManager.NETWORK_STATE_CHANGED_ACTION.equals(intent.getAction())) {
                NetworkInfo info = intent.getParcelableExtra(WifiManager.EXTRA_NETWORK_INFO);
                if (info == null) {
                    return;
                }
                if (NetworkInfo.State.CONNECTED.equals(info.getState())) {
                    ConnService.wifiService.postValue(true);
                } else {
                    ConnService.wifiService.postValue(false);
                }
            }
        }
    }

}
